# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def nav_link(display,controller = nil,action = nil)
    if not action.nil?
        if @controller_name == controller 
	  return "<li>" + link_to(display,{:controller=>controller,:action=>action},:class=>"current") + "</li>"
	else
	  return "<li>" + link_to(display,{:controller=>controller,:action=>action}) + "</li>"
	end 
    else
       if @controller_name == controller.split("/").last
	  return "<li>" + link_to(display,controller,:class=>"current") + "</li>"
       else
	  return "<li>" + link_to(display,controller) + "</li>"
       end
    end
  end
  def com_link(display,controller = nil,action = nil)
    if not action.nil?
        if @controller_name == controller 
	  return link_to(display,{:controller=>controller,:action=>action},:class=>"com_current")
	else
	  return link_to(display,{:controller=>controller,:action=>action},:class=>'com')
	end 
    else
       if @controller_name == controller.split("/").last
	  if params[:project_id]
	  return link_to(display,controller,:class=>"com") 
	  else
	  return link_to(display,controller,:class=>"com_current") 
	  end
       else
	  return link_to(display,controller,:class=>'com')
       end
    end
  end
  def indicator_tab
   indi = "<span id='indicator-tab' style='float:right;margin-right:20%;display:none;'>"
   indi += image_tag'indicator.gif'
   indi +="</span>"
   return indi
  end
  def indicator(i)
   indi = "<span id='indicator_#{i}' style='display:none;'>"
   indi += image_tag'indicator.gif'
   indi +="</span>"
   return indi
  end
  def select_datetime(datetime = Time.now, options = {})
        select_year(datetime, options) + "year".t + select_month(datetime, options) + "month".t + select_day(datetime, options) + "day".t + " &nbsp; " + select_hour(datetime, options) + "hour".t + select_minute(datetime, options) + "min".t
  end
  def select_hour_min(datetime = Time.now, options = {})
        select_hour(datetime, options) + "hour".t + select_minute(datetime, options) + "min".t
  end

  def icon(type,size=nil)
     type = FILE_EXT[type.downcase] || "unk"
     if size == 16
      "<img src=/images/icon/" + type + "16.png border=0>"
     else
      "<img src=/images/icon/" + type + ".png border=0>"
     end
  end
  def swf_report(name,data,height)
     str = ""
     str << "<div id=\"DeliveryGraph\"></div>\n"
     str << "<script type=\"text/javascript\">\n"
     str << " var activity = new FusionCharts(\"/flash/#{name}.swf\", \"ChartId\", screen.width * 0.65, \"#{height}\");\n"
     str << "activity.setDataXML(\"#{data}\");\n"
     str << "activity.render(\"DeliveryGraph\");\n"
     str << "</script>"
     str 
  end
  def swf_chart()
        str = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"  WIDTH=\"650\" HEIGHT=\"350\" id=\"FC_2_3_Column3D\" ALIGN=\"\">"
	str << "		 <PARAM NAME=movie VALUE=\"/flash/FCF_Column3D.swf\">"
	str << "		 <PARAM NAME=FlashVars VALUE=\"&dataURL=/projects/213/data.xml&chartWidth=650&chartHeight=350\">"
	str << "		 <PARAM NAME=quality VALUE=high>"
	str << "		 <PARAM NAME=bgcolor VALUE=#FFFFFF>"
	str << "		 <EMBED src=\"/flash/FCF_Column3D.swf\" FlashVars=\"&dataURL=/projects/213/data.xml&chartWidth=650&chartHeight=350\" quality=high bgcolor=#FFFFFF  WIDTH=\"650\" HEIGHT=\"350\" NAME=\"FC_2_3_Column3D\" ALIGN=\"\"  TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED>"
	str << "		</OBJECT>"
        str 
  end
  def time_label(cls,txt)
     str = "" 
     str << "<div style=\"height:15px;margin-bottom:0px;margin-top:10px;\">"
     str << "<div class=#{cls}>" 
     str << txt 
     str << "</div>"
     str << "</div>"
     str 
  end
  def time_flag(time)
    if time.strftime("%y-%m-%d") == Time.now.strftime("%y-%m-%d") 
      time_label("time_label_pre","TODAY".t) 
    else
      time_label('time_label',time_ago_in_words(time) + " ago".t + "[" + time.strftime("%y-%m-%d") + " " + time.strftime("%a").t + "]" )
    end
  end
  def logo_display(company)
       path = "#{RAILS_ROOT}/public/files/logos/#{company.id}/logo.gif"
       
       "<img src =\"/files/logos/#{company.id}/logo.gif\" style=\"margin:10px;\">" if File.exists?(path)
  end

  def feature( name )
     str = ""
     feature = Feature.find_by_name( name )
     if feature
       str << "<div class=\"tour_sec\">" 
       str << "<h2>#{feature.label_cn.to_s}</h2>"
       str << "#{feature.title_cn.to_s}<br/>"
       str << "<img src=/files/features/#{feature.id}.jpg>" if File.exists?("#{RAILS_ROOT}/public/files/features/#{feature.id}.jpg")
       str << "<br/>"
       str << feature.intro_cn.to_s
       str << "</div>"
     else
       f = Feature.new 
       f.name = name
       f.save
     end

     str
  end
  def fckeditor_text( id , toolbar=nil, value = nil)
     str = ""
     str << "<script type=\"text/javascript\">\n"
     str << "var oFCKeditor = new FCKeditor('" + id + "');\n"
     str << "oFCKeditor.BasePath = \"/fckeditor/\";\n"
     str << "oFCKeditor.Config['CustomConfigurationsPath'] = '/javascripts/fckconfig_simple.js';\n"
     str << "oFCKeditor.Config['DefaultLanguage'] = 'zh-CN';\n"
     str << "oFCKeditor.ToolbarSet = '"+ toolbar +"';\n"
     str << "oFCKeditor.Width = screen.width * 0.54;\n"
     if toolbar == "message"
     str << "oFCKeditor.Height = screen.height/3;\n"
     else
     str << "oFCKeditor.Height = screen.height/2;\n"
     end
     #str << "oFCKeditor.Value = '';\n"
     #str << "oFCKeditor.SetHTML('" + value + "');\n" unless value.nil?
     #str << "oFCKeditor.Value = '" + value + "';\n" unless value.nil?
     str << "oFCKeditor.Create();\n"
     str << "</script>"
     return str
  end
end












